#!/usr/bin/env python
# -*- coding: utf-8 -*-
#===============================================================================
# Copyright 2011 zod.yslin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
# Author: zod.yslin
# Email: 
# File Name: getargspec.py
# Description: 
#   In addition to the documentation for a function or method, it is possible to 
#   ask for a complete specification of the arguments the callable takes,
#   including default values.
#
#   The getargspec() function returns a tuple containing the list of positional 
#   argument names, the name of any variable positional arguments (e.g., *args),
#   the names of any variable named arguments (e.g., **kwds), and default values 
#   for the arguments. If there are default values, they match up with the end of
#   the positional argument list.
# Edit History: 
#   2011-11-02    File created.
#===============================================================================
import inspect
import example

arg_spec = inspect.getargspec(example.module_level_function)
print 'NAMES   :', arg_spec[0]
print '*       :', arg_spec[1]
print '**      :', arg_spec[2]
print 'defaults:', arg_spec[3]

args_with_defaults = arg_spec[0][-len(arg_spec[3]):]
print 'args & defaults:', zip(args_with_defaults, arg_spec[3])
